package com.gxa.service.impl;

import com.gxa.common.PaginationResult;
import com.gxa.mapper.FinenessMapper;
import com.gxa.pojo.*;
import com.gxa.service.FinenessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: zxy
 * Date: 2020/10/30 9:59
 * Description:
 * Version: V1.0
 */
@Service
public class FinenessServiceImpl implements FinenessService{

    @Autowired(required = false)
    private FinenessMapper finenessMapper;

    @Override
    public int addConis(Conis conis) {
        return finenessMapper.addConis(conis);
    }
    @Override
    public PaginationResult queryConis(int currentPage, int pageSize) {
        PaginationResult paginationResult = new PaginationResult();
        //当前页码数
        paginationResult.setCurrentPage(currentPage);
        //每页显示条数
        paginationResult.setPageSize(pageSize);
        //总条数
        int totalSize = getTotalSizeConis();
        //总页数
        int totalPage = totalSize / pageSize;
        if(totalSize % pageSize !=0){
            totalPage +=1;
        }
        paginationResult.setTotalPage(totalPage);
        paginationResult.setTotalSize(totalSize);
        int param1 = (currentPage-1)*pageSize;
        int param2 = pageSize;
        List<Conis> conisList =  finenessMapper.queryConis(param1,param2);
        paginationResult.setData(conisList);
        return paginationResult;
    }
    @Override
    public int updateConis(Conis conis) {
        return finenessMapper.updateConis(conis);
    }
    @Override
    public int delConis(int conisId) {
        return finenessMapper.delConis(conisId);
    }


    @Override
    public int addCommisTyp(CommisTyp commisTyp) {
        return finenessMapper.addCommisTyp(commisTyp);
    }
    @Override
    public PaginationResult queryCommisTyp(int currentPage, int pageSize) {
        PaginationResult paginationResult = new PaginationResult();
        //当前页码数
        paginationResult.setCurrentPage(currentPage);
        //每页显示条数
        paginationResult.setPageSize(pageSize);
        //总条数
        int totalSize = getTotalSizeCommisTyp();
        //总页数
        int totalPage = totalSize / pageSize;
        if(totalSize % pageSize !=0){
            totalPage +=1;
        }
        paginationResult.setTotalPage(totalPage);
        paginationResult.setTotalSize(totalSize);
        int param1 = (currentPage-1)*pageSize;
        int param2 = pageSize;
        List<CommisTyp> commisTypList =  finenessMapper.queryCommisTyp(param1,param2);
        paginationResult.setData(commisTypList);
        return paginationResult;
    }
    @Override
    public int updateCommisTyp(CommisTyp commisTyp) {
        return finenessMapper.updateCommisTyp(commisTyp);
    }
    @Override
    public int delCommisTyp(int commisTypId) {
        return finenessMapper.delCommisTyp(commisTypId);
    }


    @Override
    public int addCoditSer(CoditSer coditSer) {
        return finenessMapper.addCoditSer(coditSer);
    }
    @Override
    public PaginationResult queryCoditSer(int currentPage, int pageSize) {
        PaginationResult paginationResult = new PaginationResult();
        //当前页码数
        paginationResult.setCurrentPage(currentPage);
        //每页显示条数
        paginationResult.setPageSize(pageSize);
        //总条数
        int totalSize = getTotalSizeCoditSer();
        //总页数
        int totalPage = totalSize / pageSize;
        if(totalSize % pageSize !=0){
            totalPage +=1;
        }
        paginationResult.setTotalPage(totalPage);
        paginationResult.setTotalSize(totalSize);
        int param1 = (currentPage-1)*pageSize;
        int param2 = pageSize;
        List<CoditSer> coditSerList =  finenessMapper.queryCoditSer(param1,param2);
        paginationResult.setData(coditSerList);
        return paginationResult;
    }
    @Override
    public int updateCoditSer(CoditSer coditSer) {
        return finenessMapper.updateCoditSer(coditSer);
    }
    @Override
    public int delCoditSer(int coditSerId) {
        return finenessMapper.delCoditSer(coditSerId);
    }


    @Override
    public int addCoditClass(CoditClass coditClass) {
        return finenessMapper.addCoditClass(coditClass);
    }
    @Override
    public PaginationResult queryCoditClass(int currentPage, int pageSize) {
        PaginationResult paginationResult = new PaginationResult();
        //当前页码数
        paginationResult.setCurrentPage(currentPage);
        //每页显示条数
        paginationResult.setPageSize(pageSize);
        //总条数
        int totalSize = getTotalSizeCoditClass();
        //总页数
        int totalPage = totalSize / pageSize;
        if(totalSize % pageSize !=0){
            totalPage +=1;
        }
        paginationResult.setTotalPage(totalPage);
        paginationResult.setTotalSize(totalSize);
        int param1 = (currentPage-1)*pageSize;
        int param2 = pageSize;
        List<CoditClass> coditClassList =  finenessMapper.queryCoditClass(param1,param2);
        paginationResult.setData(coditClassList);
        return paginationResult;
    }
    @Override
    public int updateCoditClass(CoditClass coditClass) {
        return finenessMapper.updateCoditClass(coditClass);
    }
    @Override
    public int delCoditClass(int coditClassId) {
        return finenessMapper.delCoditClass(coditClassId);
    }


    @Override
    public int addWeightUnit(WeightUnit weightUnit) {
        return finenessMapper.addWeightUnit(weightUnit);
    }
    @Override
    public PaginationResult queryWeightUnit(int currentPage, int pageSize) {
        PaginationResult paginationResult = new PaginationResult();
        //当前页码数
        paginationResult.setCurrentPage(currentPage);
        //每页显示条数
        paginationResult.setPageSize(pageSize);
        //总条数
        int totalSize = getTotalSizeWeightUnit();
        //总页数
        int totalPage = totalSize / pageSize;
        if(totalSize % pageSize !=0){
            totalPage +=1;
        }
        paginationResult.setTotalPage(totalPage);
        paginationResult.setTotalSize(totalSize);
        int param1 = (currentPage-1)*pageSize;
        int param2 = pageSize;
        List<WeightUnit> weightUnitList =  finenessMapper.queryWeightUnit(param1,param2);
        paginationResult.setData(weightUnitList);
        return paginationResult;
    }
    @Override
    public int updateWeightUnit(WeightUnit weightUnit) {
        return finenessMapper.updateWeightUnit(weightUnit);
    }
    @Override
    public int delWeightUnit(int weightUnitId) {
        return finenessMapper.delWeightUnit(weightUnitId);
    }


    @Override
    public int addGoldPrice(GoldPrice goldPrice) {
        return finenessMapper.addGoldPrice(goldPrice);
    }
    @Override
    public PaginationResult queryGoldPrice(int currentPage, int pageSize) {
        PaginationResult paginationResult = new PaginationResult();
        //当前页码数
        paginationResult.setCurrentPage(currentPage);
        //每页显示条数
        paginationResult.setPageSize(pageSize);
        //总条数
        int totalSize = getTotalSizeGoldPrice();
        //总页数
        int totalPage = totalSize / pageSize;
        if(totalSize % pageSize !=0){
            totalPage +=1;
        }
        paginationResult.setTotalPage(totalPage);
        paginationResult.setTotalSize(totalSize);
        int param1 = (currentPage-1)*pageSize;
        int param2 = pageSize;
        List<GoldPrice> goldPriceList =  finenessMapper.queryGoldPrice(param1,param2);
        paginationResult.setData(goldPriceList);
        return paginationResult;
    }
    @Override
    public int updateGoldPrice(GoldPrice goldPrice) {
        return finenessMapper.updateGoldPrice(goldPrice);
    }
    @Override
    public int delGoldPrice(int priceId) {
        return finenessMapper.delGoldPrice(priceId);
    }


    public int getTotalSizeConis() {
        return finenessMapper.getTotalSizeConis();
    }
    public int getTotalSizeCommisTyp() {
        return finenessMapper.getTotalSizeCommisTyp();
    }
    public int getTotalSizeCoditSer() {
        return finenessMapper.getTotalSizeCoditSer();
    }
    public int getTotalSizeCoditClass() {
        return finenessMapper.getTotalSizeCoditClass();
    }
    public int getTotalSizeWeightUnit() {
        return finenessMapper.getTotalSizeWeightUnit();
    }
    public int getTotalSizeGoldPrice() {
        return finenessMapper.getTotalSizeGoldPrice();
    }

    /**
     * 查询成色设置
     * @param currentPage
     * @param pageSize
     * @return
     */
    @Override
    public PaginationResult queryFileness(int currentPage, int pageSize) {
        PaginationResult paginationResult = new PaginationResult();
        //当前页码数
        paginationResult.setCurrentPage(currentPage);
        //每页显示条数
        paginationResult.setPageSize(pageSize);
        //总条数
        int totalSize = getFilenessSizeNorms();
        //总页数
        int totalPage = totalSize / pageSize;
        if(totalSize % pageSize !=0){
            totalPage +=1;
        }
        paginationResult.setTotalPage(totalPage);
        paginationResult.setTotalSize(totalSize);
        int param1 = (currentPage-1)*pageSize;
        int param2 = pageSize;
        List<Fineness> finenesses = finenessMapper.queryFileness(param1,param2);
        paginationResult.setData(finenesses);
        return paginationResult;
    }

    /**
     * 修改成色设置
     * @param fineness
     * @return
     */
    @Override
    public int updateFineness(Fineness fineness) {
        return finenessMapper.updateFineness(fineness);
    }

    /**
     * 删除成色设置
     * @param fineness
     * @return
     */
    @Override
    public int delFineness(Fineness fineness) {
        return finenessMapper.delFineness(fineness);
    }

    /**
     * 添加成色设置
     * @param fineness
     * @return
     */
    @Override
    public int addFineness(Fineness fineness) {
        return finenessMapper.addFineness(fineness);
    }

    /**
     * 查询属性设置
     * @param currentPage
     * @param pageSize
     * @return
     */
    @Override
    public PaginationResult queryAttribute(int currentPage, int pageSize) {
        PaginationResult paginationResult = new PaginationResult();
        //当前页码数
        paginationResult.setCurrentPage(currentPage);
        //每页显示条数
        paginationResult.setPageSize(pageSize);
        //总条数
        int totalSize = getAttributeSizeNorms();
        //总页数
        int totalPage = totalSize / pageSize;
        if(totalSize % pageSize !=0){
            totalPage +=1;
        }
        paginationResult.setTotalPage(totalPage);
        paginationResult.setTotalSize(totalSize);
        int param1 = (currentPage-1)*pageSize;
        int param2 = pageSize;
        List<Attribute> attributes = finenessMapper.queryAttribute(param1,param2);
        paginationResult.setData(attributes);
        return paginationResult;
    }

    /**
     * 更新属性设置
     * @param attribute
     * @return
     */
    @Override
    public int updateAttribute(Attribute attribute) {
        return finenessMapper.updateAttribute(attribute);
    }

    /**
     * 删除属性设置
     * @param attribute
     * @return
     */
    @Override
    public int delAttribute(Attribute attribute) {
        return finenessMapper.delAttribute(attribute);
    }

    /**
     * 添加属性
     * @param attribute
     * @return
     */
    @Override
    public int addAttribute(Attribute attribute) {
        return finenessMapper.addAttribute(attribute);
    }

    /**
     * 查询款式分类
     * @param currentPage
     * @param pageSize
     * @return
     */
    @Override
    public PaginationResult queryStyle(int currentPage, int pageSize) {
        PaginationResult paginationResult = new PaginationResult();
        //当前页码数
        paginationResult.setCurrentPage(currentPage);
        //每页显示条数
        paginationResult.setPageSize(pageSize);
        //总条数
        int totalSize = getStyleSizeNorms();
        //总页数
        int totalPage = totalSize / pageSize;
        if(totalSize % pageSize !=0){
            totalPage +=1;
        }
        paginationResult.setTotalPage(totalPage);
        paginationResult.setTotalSize(totalSize);
        int param1 = (currentPage-1)*pageSize;
        int param2 = pageSize;
        List<Style> styles = finenessMapper.queryStyle(param1,param2);
        paginationResult.setData(styles);
        return paginationResult;
    }

    /**
     * 更新款式分类
     * @param style
     * @return
     */
    @Override
    public int updateStyle(Style style) {
        return finenessMapper.updateStyle(style);
    }

    /**
     * 删除款式分类
     * @param style
     * @return
     */
    @Override
    public int delStyle(Style style) {
        return finenessMapper.delStyle(style);
    }

    /**
     * 添加款式分类
     * @param style
     * @return
     */
    @Override
    public int addStyle(Style style) {
        return finenessMapper.addStyle(style);
    }

    /**
     * 查询商品类型
     * @param currentPage
     * @param pageSize
     * @return
     */
    @Override
    public PaginationResult queryCoditTyp(int currentPage, int pageSize) {
        PaginationResult paginationResult = new PaginationResult();
        //当前页码数
        paginationResult.setCurrentPage(currentPage);
        //每页显示条数
        paginationResult.setPageSize(pageSize);
        //总条数
        int totalSize = getCoditTypSizeNorms();
        //总页数
        int totalPage = totalSize / pageSize;
        if(totalSize % pageSize !=0){
            totalPage +=1;
        }
        paginationResult.setTotalPage(totalPage);
        paginationResult.setTotalSize(totalSize);
        int param1 = (currentPage-1)*pageSize;
        int param2 = pageSize;
        List<CoditTyp> coditTyps = finenessMapper.queryCoditTyp(param1,param2);
        paginationResult.setData(coditTyps);
        return paginationResult;
    }

    /**
     * 更新商品编码类型
     * @param coditTyp
     * @return
     */
    @Override
    public int updateCoditTyp(CoditTyp coditTyp) {
        return finenessMapper.updateCoditTyp(coditTyp);
    }

    /**
     * 删除商品编码类型
     * @param coditTyp
     * @return
     */
    @Override
    public int delCoditTyp(CoditTyp coditTyp) {
        return finenessMapper.delCoditTyp(coditTyp);
    }

    /**
     * 添加商品编码类型
     * @param coditTyp
     * @return
     */
    @Override
    public int addCoditTyp(CoditTyp coditTyp) {
        return finenessMapper.addCoditTyp(coditTyp);
    }

    /**
     * 查询含金量
     * @param currentPage
     * @param pageSize
     * @return
     */
    @Override
    public PaginationResult queryGoldCont(int currentPage, int pageSize) {
        PaginationResult paginationResult = new PaginationResult();
        //当前页码数
        paginationResult.setCurrentPage(currentPage);
        //每页显示条数
        paginationResult.setPageSize(pageSize);
        //总条数
        int totalSize = getGoldContSizeNorms();
        //总页数
        int totalPage = totalSize / pageSize;
        if(totalSize % pageSize !=0){
            totalPage +=1;
        }
        paginationResult.setTotalPage(totalPage);
        paginationResult.setTotalSize(totalSize);
        int param1 = (currentPage-1)*pageSize;
        int param2 = pageSize;
        List<GoldCont> goldConts = finenessMapper.queryGoldCont(param1,param2);
        paginationResult.setData(goldConts);
        return paginationResult;
    }

    /**
     * 修改含金量
     * @param goldCont
     * @return
     */
    @Override
    public int updateGoldCont(GoldCont goldCont) {
        return finenessMapper.updateGoldCont(goldCont);
    }

    /**
     * 删除含金量
     * @param goldCont
     * @return
     */
    @Override
    public int delGoldCont(GoldCont goldCont) {
        return finenessMapper.delGoldCont(goldCont);
    }

    /**
     * 添加含金量
     * @param goldCont
     * @return
     */
    @Override
    public int addGoldCont(GoldCont goldCont) {
        return finenessMapper.addGoldCont(goldCont);
    }

    /**
     * 查询旧料
     * @param currentPage
     * @param pageSize
     * @return
     */
    @Override
    public PaginationResult queryRecovery(int currentPage, int pageSize) {
        PaginationResult paginationResult = new PaginationResult();
        //当前页码数
        paginationResult.setCurrentPage(currentPage);
        //每页显示条数
        paginationResult.setPageSize(pageSize);
        //总条数
        int totalSize = getRecoverySizeNorms();
        //总页数
        int totalPage = totalSize / pageSize;
        if(totalSize % pageSize !=0){
            totalPage +=1;
        }
        paginationResult.setTotalPage(totalPage);
        paginationResult.setTotalSize(totalSize);
        int param1 = (currentPage-1)*pageSize;
        int param2 = pageSize;
        List<Recovery> recoveries = finenessMapper.queryRecovery(param1,param2);
        paginationResult.setData(recoveries);
        return paginationResult;
    }

    /**
     * 更新旧料
     * @param recovery
     * @return
     */
    @Override
    public int updateRecovery(Recovery recovery) {
        return finenessMapper.updateRecovery(recovery);
    }

    /**
     * 删除旧料
     * @param recovery
     * @return
     */
    @Override
    public int delRecovery(Recovery recovery) {
        return finenessMapper.delRecovery(recovery);
    }

    /**
     * 添加旧料
     * @param recovery
     * @return
     */
    @Override
    public int addRecovery(Recovery recovery) {
        return finenessMapper.addRecovery(recovery);
    }

    /**
     * 总旧料
     * @return
     */
    private int getRecoverySizeNorms() {
        return finenessMapper.getRecoverySizeNorms();
    }

    /**
     * 总类型编码
     * @return
     */
    private int getCoditTypSizeNorms() {
        return finenessMapper.getCoditTypSizeNorms();
    }

    /**
     * 总款式分类设置
     * @return
     */
    private int getStyleSizeNorms() {
        return finenessMapper.getStyleSizeNorms();
    }

    /**
     * 总属性
     * @return
     */
    private int getAttributeSizeNorms() {
        return finenessMapper.getAttributeSizeNorms();
    }

    /**
     * 总成色设置
     * @return
     */
    private int getFilenessSizeNorms() {
        return finenessMapper.getFilenessSizeNorms();
    }

    /**
     * 总含金量
     * @return
     */
    public int getGoldContSizeNorms() {
        return finenessMapper.getGoldContSizeNorms();
    }
}
